Spread.Services Documentation
Data Label
Spread.Services Documentation > Developer's Guide > Manage Data in Spread Component > Use Chart > Customize Chart Objects > Data Label

Spread.Services allows you to insert data labels in a chart to ensure the information depicted in it can be easily interpreted and visualized. You can add data labels in a chart using the properties and methods of the IPoint interface and the ISeries interface.

Refer to the following example code to set data labels in a chart and customize the data label text.

C#
Copy Code
worksheet.Range["A1:D6"].Value = new object[,]
{
    {null, "S1", "S2", "S3"},
    {"Item1", 10, 25, 25},
    {"Item2", -51, -36, 27},
    {"Item3", 52, -85, -30},
    {"Item4", 22, 65, 65},
    {"Item5", 23, 69, 69}
};

//Set Series' all data labels and specific data label's format.
IShape shape1 = worksheet.Shapes.AddChart(ChartType.ColumnClustered, 200, 50, 300, 300);
shape1.Chart.SeriesCollection.Add(worksheet.Range["A1:D6"], RowCol.Columns, true, true);
ISeries series1 = shape1.Chart.SeriesCollection[0];
series1.HasDataLabels = true;
//set series1's all data label's format.
series1.DataLabels.Format.Fill.Color.RGB = Color.Green;
series1.DataLabels.Format.Line.Color.RGB = Color.Red;
series1.DataLabels.Format.Line.Weight = 3;
//set series1's specific data label's format.
series1.DataLabels[2].Format.Fill.Color.RGB = Color.Yellow;
series1.Points[2].DataLabel.Format.Line.Color.RGB = Color.Blue;
series1.Points[2].DataLabel.Format.Line.Weight = 5;

//Customize data label's text.
IShape shape2 = worksheet.Shapes.AddChart(ChartType.ColumnClustered, 550, 50, 300, 300);
shape2.Chart.SeriesCollection.Add(worksheet.Range["A1:D6"], RowCol.Columns, true, true);
ISeries series2 = shape2.Chart.SeriesCollection[0];
series2.HasDataLabels = true;
//customize data lables' text.
series2.DataLabels.ShowCategoryName = true;
series2.DataLabels.ShowSeriesName = true;
series2.DataLabels.ShowLegendKey = true;